package com.pipodi.itasamobile.model;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.client.ClientProtocolException;

import com.pipodi.itasamobile.R;
import com.pipodi.itasamobile.connections.ConnectionForSubtitle;
import com.pipodi.itasamobile.connections.POSTCallLoginItaSA;
import com.pipodi.itasamobile.model.interfaces.SubtitleInterface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

public class Subtitle implements SubtitleInterface {

	private int ID;
	private String episode;
	private String name;
	private String version;

	public Subtitle(int ID, String name, String episode, String version) {
		this.ID = ID;
		this.name = name;
		this.episode = episode;
		this.version = version;
	}

	@Override
	public int getID() {
		return this.ID;
	}

	@Override
	public String getShowName() {
		return this.name;
	}

	@Override
	public String getVersion() {
		return this.version;
	}

	@Override
	public View getView(LayoutInflater inflater, View convertView) {
		if (convertView == null) {
			convertView = (View) inflater.inflate(
					R.layout.sub_list_item_layout, null);
		}

		TextView showName = (TextView) convertView
				.findViewById(R.id.sub_showName);
		TextView episode = (TextView) convertView.findViewById(R.id.sub_epNum);
		TextView version = (TextView) convertView
				.findViewById(R.id.sub_version);
		ImageButton downloadButton = (ImageButton) convertView.findViewById(R.id.downloadButton);
		downloadButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ConnectionForSubtitle connection = new ConnectionForSubtitle(ID);
				connection.execute("");
				Log.e("CONNECTION", "Dopo Authcode");
			}
		});
		showName.setText(this.name);
		episode.setText(this.episode);
		version.setText(this.version);
		
		return convertView;
	}

	@Override
	public String getEpisode() {
		return this.episode;
	}

	@Override
	public String toString() {
		return "[ID:" + this.ID + " ; Name:" + this.name + " ; Episode:"
				+ this.episode + " ; Version:" + this.version + "]";
	}

}
